package com.zzty.zzlp.dao;

import com.zzty.zzlp.entity.User;
import com.zzty.zzlp.entity.User_info;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

    @Insert("insert into user (name,password,email,type,code,state,disname ) values (#{name},#{password},#{email},#{type},#{code},#{state},#{name})")
    public Integer addUserByMail(User user);

    @Insert("insert into user_info (user_id,photo,mail,phone) values (#{user_id},#{photo},#{mail},#{phone})")
    public void addUserInfo(User_info user_info);

    @Update("update user set state = 1 where id = #{id}")
    public Integer setState(@Param("id") Integer id);

    @Select("select * from user where code = #{code}")
    public User findUserByCode(@Param("code") String code);

    @Update("update user set code = '' where id = #{id}")
    public Integer delCode(@Param("id") Integer id);

    @Select("select name from user where name = #{name} and state = 1")
    public List<String> searchRepeatedName(@Param("name") String name);

    @Select("select email from user where email = #{email} and state = 1")
    public List<String> searchRepeatedEmail(@Param("email") String email);

    @Select("select tel from user where tel = #{tel} and state = 1")
    public List<String> searchRepeatedTel(@Param("tel") String tel);

    @Select("select * from user where email = #{email} and password = #{password} and state = 1")
    public User searchUserByEmailAndPwd(@Param("email") String email, @Param("password") String password);

    @Select("select * from user where tel = #{tel} and password = #{password} and state = 1")
    public User searchUserByTelAndPwd(@Param("tel") String tel, @Param("password") String password);

    @Insert("insert into user (name,password,tel,type,state,disname ) values (#{name},#{password},#{tel},#{type},#{state},#{name})")
    public Integer addUserByTel(User user);

    @Update("update user set pwdRepaire = #{pwdRepaire} where email = #{email} and state = 1")
    public Integer emailPwdRepaire(User user);

    @Update("update user set password = #{password} where pwdRepaire = #{pwdRepaire}")
    public Integer changePwdByMail(User user);

    @Update("update user set password = #{password} where tel = #{tel}")
    public Integer changePwdByTel(User user);

    @Select("select * from user where pwdRepaire = #{pwdRepaire}")
    public User searchUserByPwdRepaire(@Param("pwdRepaire") String pwdRepaire);

    @Update("update user set pwdRepaire = '' where id = #{id}")
    public Integer delPwdRepaire(@Param("id") Integer id);

    @Select("select * from user where id = #{id} and state = 1")
    public User selectUserById(@Param("id") Integer id);

    @Select("select * from user where name = #{name} and state = 1")
    public User selectUserByName(@Param("name") String name);

    @Select("select * from user where name = #{name} and state = 1")
    public User getUserByName(String name);

    @Select("select Id from user where clazzId=#{clazzId} and type=1")
    public List<Integer> searchStuIdByclazzId(@Param("clazzId") Integer clazzId);

    @Select("select * from user where type = 1")
    public List<User> searchAllStudent();

    @Update("update user set clazzId = #{clazzId} where id = #{id}")
    public Integer changeClazzById(User user);

    @Update("update user set password = #{password} where id = #{id}")
    public void changPwdById(User user);
}
